#include "qtimage.hpp"

Qtimage::Qtimage(const unsigned int _height,const unsigned int _width) {
	height = _height;
	width = _width;
	image = new QImage(height,width,QImage::Format_RGB32);

}
Qtimage::~Qtimage(void) {
	delete image;
}
void Qtimage::set_pixel(unsigned int px,unsigned int py,const Color& _color) {
	double r = _color.get_r();
	double g = _color.get_g();
	double b = _color.get_b();
	
	py = height - py;	
	if (px > width-1) px = width-1;
	
	if (py > height-1) py = height-1;
	
	int ir = (int) (r * 255.0);
	int ig = (int) (g * 255.0);
	int ib = (int) (b * 255.0);

	ir = max(0,min(ir,255));
	ig = max(0,min(ig,255));		
	ib = max(0,min(ib,255));

	QRgb color;
	color = qRgb(ir,ig,ib);
	image->setPixel(px,py,color);

}

void Qtimage::save_file(const char* _arq) {
	image->save(_arq);
}

QImage* Qtimage::get_QImage(void) const {
	return image;
}
